/*
 *所有关于WarehouseoutintoDTO类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*WarehouseoutintoDTOService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using VOL.Core.BaseProvider;
using VOL.Core.Extensions.AutofacManager;
using VOL.Entity.DomainModels;
using System.Linq;
using VOL.Core.Utilities;
using System.Linq.Expressions;
using VOL.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using WareHouse.Write.System.IRepositories;
using System.Collections.Generic;
using SqlSugar;
using VOL.Core.DBManager;

namespace WareHouse.Write.System.Services
{
    public partial class WarehouseoutintoDTOService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IWarehouseoutintoDTORepository _repository;//访问数据库
        private readonly ISqlSugarClient _db;
        [ActivatorUtilitiesConstructor]
        public WarehouseoutintoDTOService(
            IWarehouseoutintoDTORepository dbRepository,
            IHttpContextAccessor httpContextAccessor,
            ISqlSugarClient db
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            _db = db;
          
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }
      //  WebResponseContent webResponse = new WebResponseContent();
        //public override WebResponseContent Add(SaveModel saveDataModel)
        //{

        //    AddOnExecuting = (WarehouseoutintoDTO order, object list) =>
        //    {
        //        //明细表对象
        //        List<WarehouseoutintoDTO> orderLists = list as List<WarehouseoutintoDTO>;

        //        //自定义逻辑
        //        if (orderLists == null || orderLists.Count == 0)
        //        {//如果没有界面上没有填写明细，则中断执行
        //            return webResponse.Error("必须填写出库详细信息");
        //        }
        //        var orders = _db.Queryable<WarehouseoutintoDTO>().OrderByDescending(c => c.WarehouseoutintoDTOid);
        //        int numberstring = int.Parse(orders.FirstOrDefault().WarehouseoutintoDTOid) + 1;
        //        order.WarehouseoutintoDTOid = numberstring.ToString().PadLeft(7, '0');
        //        order.IsDel = 0;

        //        //设置webResponse.Code = "-1"会中止后面代码执行，与返回 webResponse.Error()一样，区别在于前端提示的是成功或失败
        //        //webResponse.Code = "-1";
        //        // webResponse.Message = "测试强制返回";
        //        //return webResponse.OK("ok");

        //        return webResponse.OK();
        //    };
        //    return base.Add(saveDataModel);
        //}
    }
}
